package fr.afcepf.ai89.esharing.metier;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import fr.afcepf.ai89.esharing.data.IDAOEmprunt;
import fr.afcepf.ai89.esharing.data.IDAOFrNoTel;
import fr.afcepf.ai89.esharing.data.IDAOProprietaire;
import fr.afcepf.ai89.esharing.entity.Proprietaire;

public class BusinessParrainage implements IBusinessParrainage {

	@Override
	public int parrainer(Proprietaire parrain, Proprietaire filleul) {
		
		int id = 0;
		
		try {
			
			Context ctx;
			ctx = new InitialContext();
			IDAOProprietaire proxyDataProprietaire = null;
			IDAOFrNoTel proxyDataTel=null;
			
			try {
				
				proxyDataProprietaire = (IDAOProprietaire)ctx.lookup("java:global/ESharingPhase1/DAOProprietaire!fr.afcepf.ai89.esharing.data.IDAOProprietaire");
				proxyDataTel = (IDAOFrNoTel)ctx.lookup("java:global/ESharingPhase1/DAOFrNoTel!fr.afcepf.ai89.esharing.data.IDAOFrNoTel");
			
			}
			catch (Exception e ) {
				
				proxyDataProprietaire = (IDAOProprietaire)ctx.lookup("ESharingPhase1/DAOProprietaire!fr.afcepf.ai89.esharing.data.IDAOProprietaire");
				proxyDataTel = (IDAOFrNoTel)ctx.lookup("ESharingPhase1/DAOFrNoTel!fr.afcepf.ai89.esharing.data.IDAOFrNoTel");
			
			}
			
			
			//msg = proxyDataMsg.getMsgP.rive(idMsgPrive);
			proxyDataTel.addNoTel(filleul.getFrNoTel1());
			
			id = proxyDataProprietaire.inscrire(filleul);
				
		}
		catch (NamingException e) {
			
			e.printStackTrace();
			
		}
		
		return id;
		
	}

}
